#include<iostream>
#include<cstring>
using namespace std;
const int N = 5e5 + 10;
int tree[N][26], p[N], e[N];
int idx,cur;

void insert(string& s)
{
	cur = 0;
	p[cur]++;
	for (auto it : s)
	{
		int i = it - 'a';
		if (tree[cur][i] == 0)tree[cur][i] = ++idx;
		cur = tree[cur][i];
		p[cur]++;
	}
	e[cur]++;
}

int find(string& s)
{
	cur = 0;
	for (auto it : s)
	{
		int i = it - 'a';
		if (tree[cur][i] == 0)return 0;
		cur = tree[cur][i];
	}
		if (e[cur] > 0)
		{
			int t = e[cur];
			e[cur] = -1;
			return t;
		}
	return e[cur];
}

int main()
{
	int n, t;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		string s;
		cin >> s;
		insert(s);
	}
	cin >> t;
	while (t--)
	{
		string s1;
		cin >> s1;
		int ret = find(s1);
		if (ret == 0)cout << "WRONG" << endl;
		else if (ret > 0)cout << "OK" << endl;
		else cout << "REPEAT" << endl;
	}
	return 0;
}

